package cn.hairui.blog.dao;

import cn.hairui.blog.entity.Albumimg;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 相册照片表 Mapper 接口
 * </p>
 *
 * @author laoganbu
 * @since 2020-04-15
 */
@Mapper
public interface AlbumimgMapper extends BaseMapper<Albumimg> {

    @Select("SELECT  ID AS pid,IMG_PATH AS src,IMG_PATH AS thumb,CASE WHEN IMG_NAME=NULL THEN '' ELSE IMG_NAME END AS alt FROM ALBUMIMG WHERE ALBUM_ID=#{id}")
    List<Map> getByAlbumId(int id);

    @Delete("delete from albumimg where IMG_NAME like CONCAT(#{name},'%')")
    void removeByName(String name);

    @Select("SELECT * FROM ALBUMIMG WHERE ALBUM_ID=#{albumId} ORDER BY ID DESC")
    List<Albumimg> findImagesByAlbumId(int albumId);
}
